﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Quickuse.Logging.FileLogger;
using System;
using System.Collections.Generic;
using System.Text;

namespace Quickuse.Logging
{
    /// <summary>
    /// FileLoggerExtensions
    /// </summary>
    public static class FileLoggerExtensions
    {
        /// <summary>
        /// AddFile
        /// </summary>
        /// <param name="builder">builder</param>
        /// <returns></returns>
        public static ILoggingBuilder AddFile(this ILoggingBuilder builder)
        {

            builder.Services.TryAddSingleton<ILoggingConfiguration, LoggingConfiguration>();
            builder.Services.TryAddSingleton<IFileLoggerSettings, FileLoggerSettings>();
            builder.Services.TryAddSingleton<FileLoggerProcessor, FileLoggerProcessor>();
            builder.Services.AddSingleton<ILoggerProvider, FileLoggerProvider>();

            return builder;
        }

        /// <summary>
        /// AddFile
        /// </summary>
        /// <param name="builder">builder</param>
        /// <param name="configuration">configuration</param>
        /// <returns></returns>
        public static ILoggingBuilder AddFile(this ILoggingBuilder builder, IConfiguration configuration)
        {
            builder.Services.TryAddSingleton<ILoggingConfiguration, LoggingConfiguration>();
            builder.Services.TryAddSingleton<IConfiguration>(configuration);
            builder.Services.TryAddSingleton<IFileLoggerSettings, FileLoggerSettings>();
            builder.Services.TryAddSingleton<FileLoggerProcessor, FileLoggerProcessor>();
            builder.Services.AddSingleton<ILoggerProvider, FileLoggerProvider>();

            return builder;
        }
    }
}
